﻿var finished=true;
function allinfo(){
    var ua = navigator.userAgent;
    ua = ua.toLowerCase();
    var match = /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) ||/(msie) ([\w.]+)/.exec(ua) || !/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) || [];
    switch(match[1]){
    case "msie":      //ie
	    if (parseInt(match[2]) === 6){   //ie6
	          //alert("ie6");
	          //alert("暂时不支持IE7.0及以下版本浏览器，请升级您的浏览器版本！");
		    	$.weeboxs.open('暂时不支持IE7.0及以下版本浏览器，请升级您的浏览器版本！', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
	    	}
	    else if (parseInt(match[2]) ===7||parseInt(match[2]) ===8||parseInt(match[2]) ===9) {
	    	$("#productselect").css("top","175px");
	    }
     break;
     default:
    	 $("#productselect div:eq(0)").attr("style","margin-top:10px;");
      break;
    }
}

var dataindex = 10;// 读了几条数据
function loadShareMsg() {
	if ($("#hiddenhasdata").val() <= dataindex) {
		$("#bottomtip font").text("--- THE -- END ---");
		$("#bottomtip font").show();
		finished=true;
	} else {
		$("#bottomtip font").text("LODING........");
		$("#bottomtip font").show();
		$("#bottomtip font").hide(1000);
		setTimeout(function() {
			$.getJSON("getMoreShare.action",{
				start : dataindex,
				recommendTime : $("#hiddenrecommendTime").val(),
				productid:$("#hiddenproductid").val()
			},
			function(data) {
				showEach(data.plist,"sharechild_container",dataindex+1);
				dataindex+=1;
			});
			finished=true;
		}, 1000);
	}
}

function jPagesresign(id, classname) {
	$("" + classname).jPages({
		containerID : id,
		first : '首页 ',
		last : ' 尾页',
		previous : ' 上页 ',
		next : ' 下页 ',
		perPage : 5,
		startPage : 1,
		startRange : 2,
		midRange : 3,
		endRange : 2,
		keyBrowse : true,
		callback : function(pages, items) {
			items.showing.find("img").trigger("turnPage");
			items.oncoming.find("img").trigger("turnPage");
		}
	});
}

function changeRecommend(i) {
	window.location.href = "showHomePage.action?recommendTime=" + i;
}
function showParticipateDetail(id, type) {
	window.location.href = "showParticipateDetail.action?id=" + id + "&&type="
			+ type;
}

function getUserMessage(a) {
	window.location.href = "getFriendOwnMessageAction?uname=" + a;
}


function sendComment(a,b,c){
	document.getElementById("plform"+c).submit();
	//alert("评论成功！");
	$.weeboxs.open('评论成功!', {
		title:'提示',
		timeout:5,
		showCancel:false,
		okBtnName: '确定',
	});
	$("#sharechild_container input[type='text']").val("");
	$("#sharechild_container input[type='file']").val("");
	$.getJSON("getCustomComm.action",{id:a,type:b,dd:new Date().getTime()},
	function(data) {// 返回新的评论信息，和评论条数
		$("#usertext" + c).html("");
		var usertext = document.getElementById("usertext" + c);
		$.each(data.clist,function(i, v) {
			if (i < 2) {
				var out = document.createElement("div");
				out.setAttribute("style","height:50px;");
				usertext.appendChild(out);
				var shiliao = document.createElement("div");
				shiliao.setAttribute("style","float:right;cursor:pointer;font-size:12px;color:blue;");
				shiliao.setAttribute("onclick","chatSomeBody('"+v.userName+"')");
				shiliao.innerHTML = "私聊";
				var jubao = document.createElement("div");
				jubao.setAttribute("style","float:right;cursor:pointer;font-size:12px;color:blue;");
				jubao.setAttribute("onclick","reportSomebody("+v.commentId+")");
				jubao.innerHTML = "举报|";
				var div1=document.createElement("div");
				div1.setAttribute("style", "width:320px;float:left;");
				out.appendChild(div1);
				div1.innerHTML+="<div style='width:290px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;float:left;'>[<a href='getFriendOwnMessageAction?uname="+v.userName+"' class='username1' style='cursor: pointer;' target='_blank'>"+v.userName+" </a>]"+v.commentContent+"</div>";
				if(v.commPic!=""&&v.commPic!=null)
					div1.innerHTML+="<a href='"+v.commPic+"' rel='lightbox'><img title='点击查看原图,右键下载图片' style='width:22px;height:22px;' src='"+v.commPic+"'/></a>";
				if(v.filePath!=""&&v.filePath!=null)
					div1.innerHTML+="<img title='下载设计文件' src='images/xiazai.png' style='width:22px;height:22px;cursor:pointer;' onclick='window.location.href=\"downloadFile1?path="+v.filePath+"&&filename="+v.fileName+"\"'/>";
				out.appendChild(shiliao);
				out.appendChild(jubao);
			}
		}
				);
		if(data.listsize>2){
			$("#moreComm"+c).html("显示更多评论(<a target='_blank' style='cursor: pointer;' href='showParticipateDetail?id="+id+"&&type="+type+"'>"+(data.listsize-2)+"</a>)");
		}else{
			$("#moreComm"+c).html("<font style='float:left;cursor:pointer;' href='javascript:;' onclick='showParticipateDetail(\""+id+"\",\""+type+"\");'>查看定制详细</font>");
		}
	});
}

function reportSomebody(a){
	$("#jubao").dialog("open");
	$("#jubaoComm").val(a);
	$("#reportReason").val("");
}
function reportClick(){
	if ($("#showusersNamea1").html() == ""
		|| $("#showusersNamea1").html() == 'null') {
		$("#login").dialog("open");
}else{
	var commid=$("#jubaoComm").val();
	var reason=$("#reportReason").val();
	$.getJSON("reportSomeBody.action",{
		commentId:commid,
		reason:reason
	});
	$("#jubao").dialog("close");
		//alert("举报成功");
		$.weeboxs.open('举报成功', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

function chatSomeBody(a){
	if ($("#showusersNamea1").html() == ""|| $("#showusersNamea1").html() == 'null') {
		$("#login").dialog("open");
	}else{
		$("#private_comm").dialog("open");
		$("#shoujianren").val(a);
	}
}

function sendMsg(){
	if ($("#showusersNamea1").html() == ""|| $("#showusersNamea1").html() == 'null') {
		$("#login").dialog("open");
	}else{
		$("#form1").submit();
	}
}

function shiliaoFasong(){
	if($.trim($("#chatContent").val())!=''){
		document.getElementById("shiliaoForm").submit();
		$("#private_comm").dialog("close");
		//alert("私聊发送成功");
		$.weeboxs.open('私聊发送成功', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
		$("#chatContent").val("");
		$("input[name='upload']").val("");
	}else{
		//alert("私聊内容不能为空！");
		$.weeboxs.open('私聊内容不能为空!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

function showEach(data,id,begin){
	var dataindex=begin;
	$.each(data,function(index, value) {
		var out=document.createElement("div");
		out.setAttribute("style", "height:237px;margin-top:10px;border:1px solid peachpuff;");
		document.getElementById(id).appendChild(out);
		var left=document.createElement("div");
		left.setAttribute("style", "float:left;");
		left.innerHTML="<img onclick='showParticipateDetail(\""+value.id+"\",\""+value.type+"\");' style='width:277px;height:233px;' src="+value.orderPic+">";
		var right=document.createElement("div");
		right.setAttribute("style", "text-align:left;");
		out.appendChild(left);
		out.appendChild(right);
		var right1=document.createElement("div");
		right1.setAttribute("style", "text-align:left;height:30px;");
		var right2=document.createElement("div");
		right2.setAttribute("style", "height:100px;");
		right2.setAttribute("id", "usertext"+(dataindex+1));
		var right3=document.createElement("div");
		right3.setAttribute("style", "height:40px;");
		right3.setAttribute("id", "moreComm"+(dataindex+1));
		var form=document.createElement("form");
		form.setAttribute("action", "insertIntoComment.action");
		form.setAttribute("id", "plform"+(dataindex+1));
		form.setAttribute("enctype", "multipart/form-data");
		form.setAttribute("name", "plform");
		form.setAttribute("target", "upload_target");
		form.setAttribute("method", "post");
		var right4=document.createElement("div");
		right4.setAttribute("style", "height:30px;");
		var right5=document.createElement("div");
		right5.setAttribute("style", "height:30px;");
		right.appendChild(right1);
		right.appendChild(right2);
		right.appendChild(right3);
		var hidd1=document.createElement("input");
		hidd1.setAttribute("type", "hidden");
		hidd1.setAttribute("name", "id");
		hidd1.setAttribute("value", value.id);
		var hidd2=document.createElement("input");
		hidd2.setAttribute("type", "hidden");
		hidd2.setAttribute("name", "type");
		hidd2.setAttribute("value", value.type);
		var iframe=document.createElement("iframe");
		iframe.setAttribute("name", "upload_target");
		iframe.setAttribute("style", "display:none");
		iframe.setAttribute("id", "upload_target");
		form.appendChild(hidd1);
		form.appendChild(hidd2);
		form.appendChild(right4);
		form.appendChild(right5);
		form.appendChild(iframe);
		right.appendChild(form);
		right1.innerHTML="[owner:<a href='getFriendOwnMessageAction?uname="+value.name+"'>"+value.name+"</a>]";
		if(value.content!='null'&&value.content!=null&&value.content!=''){
			right1.innerHTML+=value.content;
		}
		$.each(value.clist,function(i,c){
			if(i<2){
				var pl=document.createElement("div");
				pl.setAttribute("style", "height:50px;");
				var div1=document.createElement("div");
				div1.setAttribute("style", "width:320px;float:left;");
				pl.appendChild(div1);
				div1.innerHTML+="<div style='width:290px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;float:left;'>[<a href='getFriendOwnMessageAction?uname="+c.userName+"' class='username1' style='cursor: pointer;' target='_blank'>"+c.userName+" </a>]"+c.commentContent+"</div>";
				if(c.commPic!=""&&c.commPic!=null)
					div1.innerHTML+="<a href='"+c.commPic+"' rel='lightbox'><img title='点击查看原图,右键下载图片' style='width:22px;height:22px;' src='"+c.commPic+"'/></a>";
				if(c.filePath!=""&&c.filePath!=null)
					div1.innerHTML+="<img title='下载设计文件' src='images/xiazai.png' style='width:22px;height:22px;cursor:pointer;' onclick='window.location.href=\"downloadFile1?path="+c.filePath+"&&filename="+c.fileName+"\"'/>";
				var shiliao=document.createElement("div");
				shiliao.setAttribute("onclick", "chatSomeBody('"+c.userName+"')");
				shiliao.setAttribute("style", "float:right;cursor:pointer;font-size:12px;color:blue;");
				shiliao.innerHTML="私聊";
				var jubao=document.createElement("div");
				jubao.setAttribute("onclick", "reportSomebody("+c.commentId+")");
				jubao.setAttribute("style", "float:right;cursor:pointer;font-size:12px;color:blue;");
				jubao.innerHTML="举报";
				pl.appendChild(shiliao);
				pl.appendChild(jubao);
				right2.appendChild(pl);
			}
		});
		if(value.listsize!=0){
			right3.innerHTML="显示更多评论(<a onclick='showParticipateDetail(\""+value.id+"\",\""+value.type+"\");' href='javascript:;' style='cursor: pointer;'>"+value.listsize+"</a>)";
		}else{
			right3.innerHTML="<a onclick='showParticipateDetail(\""+value.id+"\",\""+value.type+"\");' href='javascript:;' style='float:left'>查看定制详细</a>";
		}
		right4.innerHTML="<input type='text' id='commenttext"+(dataindex+1)+"' value='' name='comment' style='width:300px;'>";
		right5.innerHTML="<input type='button' onclick='showUpload(this);$(this).remove();' class='btnUploadFile' value='上传图片或文件'/>" +
				"<input type='button' onclick='sendComment(\""+value.id+"\",\""+value.type+"\","+(dataindex+1)+")' style='color:rgb(122,3,3);margin-left:50px;' value='发表评论'/>";
		dataindex += 1;
				}
			);
}
function showUpload(a){
	$(a).parent().prepend("<input type='file' name='upload' style='width:220px;'/>");
	$(a).next().css("margin-left","5px");
}


